<template>
	<view class="box">
		<view class="head">
			<view class="head_left" @click="fanhui">
				<image src="http://oos-cn.ctyunapi.cn/hfclass/fanhui.png?Signature=UxKzt/fO7QiCKXVEBjkGnSGdoIw%3D&AWSAccessKeyId=65b300139cc5a0aa9572&Expires=865585101242" style="width: 16rpx;height: 30rpx;margin-right: 20rpx;"  ></image>
				<text>返回</text>
			</view>
			<view style="position: relative;left: -16rpx;">个人信息</view>
			<view class="head_right" >
				<!-- <image src="http://111.62.51.251:8081/hfclass/设置30X30.png"  style="width: 36rpx;height: 36rpx;"></image> -->
				<!-- <view class="windows" v-if="IsSet">
					<view class="windows_box">
						<view @click="appear">数据上报</view>
						<view @click="amend">信息完善</view>
						<view @click="mit">提交记录</view>
					</view>
				</view> -->
			</view>
		</view>
		<view class="dian"></view>
		<view class='content'>
			<view class="ent_head">
				<view class='names'>
					<view>姓名</view>
					<view v-if="objs.name">{{objs.name}}</view>
					<view v-else>请编辑姓名</view>
				</view>
				<view class='names'>
					<view>年龄</view>
					<view v-if="objs.age">{{objs.age}}</view>
					<view v-else>请编辑年龄</view>
				</view>
				
				<view class='names'>
					<view>身份号</view>
					<view v-if="objs.identityNumber">{{objs.identityNumber}}</view>
					<view v-else>请编辑身份证</view>
				</view>
				<view class='names'>
					<view>性别</view>
					<view v-if="sex">{{sex}}</view>
					<view v-else>请编辑性别</view>
				</view>
				<view class='names'>
					<view>职业</view>
					<view v-if="objs.title">{{objs.title}}</view>
					<view v-else>请编辑职业</view>
				</view>
				<view class='names' v-if="objs.title=='教师'||school!=''?true:false">
					<view>学校（单位）</view>
					<view v-if="objs.organ">{{school}}</view>
					<view v-else>请编辑学校</view>
				</view>
				<view class='names' v-if="objs.title=='学生'?true:false">
					<view>班级</view>
					<view v-if="objs.organ">{{Class}}</view>
					<view v-else>请编辑班级</view>
				</view>
				<view class='names'>
					<view>常住地址</view>
					<view v-if="objs.address">{{objs.address}}</view>
					<view v-else>请编辑常住地址</view>
				</view>
				<view class='names'>
					<view>家庭成员数</view>
					<view v-if="objs.familyCount">{{objs.familyCount}}</view>
					<view v-else>请编辑家庭成员数</view>
				</view>
				<view class='names opp'>
					<view>联系电话</view>
					<view v-if="objs.phoneNumber">{{objs.phoneNumber}}</view>
					<view v-else>请编辑联系电话</view>
				</view>
			</view>
			<view class="modification">
				<view  @click="amend">修改信息</view>
			</view>
		</view>
		
		<view v-if="loadModal" class="MaskLayer"></view>
		<view class="gif" v-if="loadModal">
			<view>
				<image src="http://oos-cn.ctyunapi.cn/hfclass/jiazai.gif?Signature=OgNX%2BUIeALb4HM35vCGC1jX%2BZEw%3D&AWSAccessKeyId=65b300139cc5a0aa9572&Expires=865585100785"></image>
				<view>请耐心等待！</view>
			</view>
		</view>
		
	    <view v-if="IsRelieve" class="MaskLayer"></view>
		<view class="CPM" v-if="IsRelieve">
			<view class="CPM_box">
				<image src="http://oos-cn.ctyunapi.cn/hfclass/%E5%85%B3%E9%97%AD60X60.png?Signature=VQbu8kG7wFA3irvQ97DdL4eVhpI%3D&AWSAccessKeyId=65b300139cc5a0aa9572&Expires=865585102259" @click="IsRelieve=false"></image>
				<view>请添加上报人</view>
				<view @click="confirm">确定</view>
				<view @click="IsRelieve=false">取消</view>
			</view>
		</view>
	</view>
</template>

<script>
	import App from '../../App.vue'
	export default {
		data() {
			return {
				loadModal:false,
				IsRelieve:false,
				// IsSet:false,
				objs:{},
				userId:'',
				school:'',
				Class:'',
				sex:null
			}
		},
		onLoad(op) {
			if(op){
				this.userId=op.userId
				this.getonlon()
			}
		},
		onShow() {
			// if(this.userId==0||this.userId==null||this.userId==''||this.userId==undefined){
			// 	this.gitObj()
			// }
		},
		created() {
			// let val = uni.getStorageSync('storage_key');
			// console.log(val)
			// if(this.userId==0||this.userId==null||this.userId==''||this.userId==undefined){
			// 	this.gitObj()
			// }
			// this.getopp()
		},
		methods:{
			// gitObj(){
			// 	var that=this
			// 	that.loadModal=true
			// 	uni.request({
			// 		method:'POST',
			// 		url:App.globalData.baseUrl + '/api/services/app/session/GetCurrentLoginInformations',
			// 		success(res) {
			// 			if(res.data.result==null||res.data.result.user==undefined||res.data.result.user==null||res.data.result.user==''){
			// 				that.loadModal=false
			// 				uni.showToast({
			// 					icon:'none',
			// 					duration:2000,
			// 					title:'未登录'
			// 				})
			// 				let cl=setTimeout(()=>{
			// 					window.location.href='/wx/GetCode'
			// 					clearTimeout(cl)
			// 				},2000)
			// 			}else{
			// 				that.userId=res.data.result.user.id
			// 				that.getonlon()
			// 			}
			// 		},fail(res) {
			// 			that.loadModal=false
			// 			uni.showToast({
			// 				title:res.data.error.message,
			// 				duration:1000,
			// 				icon:'none'	,
			// 			})
			// 		}
			// 	})
			// },
			getonlon(){
				let that=this
				that.loadModal=true
				uni.request({
					method:'POST',
					url:App.globalData.baseUrl + '/api/services/app/organUser/GetUserInfo',
					data:{"userId":that.userId},
					success(res) {
					    that.objs=res.data.result
					    that.sex=that.objs.sex
						
						if(that.objs.age==0&&that.objs.identityNumber.length==18){
							
							//获取年龄 
							var myDate = new Date(); 
							var month = myDate.getMonth() + 1; 
							var day = myDate.getDate(); 
							var age = myDate.getFullYear()-that.objs.identityNumber.substring(6, 10) - 1; 
							if (that.objs.identityNumber.substring(10,12)<month||that.objs.identityNumber.substring(10,12)==month&&that.objs.identityNumber.substring(12,14)<=day) 
							{ 
							  age++; 
							} 
							
							that.objs.age=age
							
						}
						
						
					    that.objs.organ.forEach((item,index)=>{
						    if(item.level==4){
							   that.school=item.name
						    }else if(item.level==5){
							   that.Class=item.name
						    }
					    })
					  // uni.setStorageSync('storage_key', that.objs);
					  that.loadModal=false
					},fail(res) {
						that.loadModal=false
						uni.showToast({
							title:res.data.error.message,
							duration:1000,
							icon:'none'	,
						})
					}
				})
			},
			mit(){
				// this.IsSet=false
				uni.navigateTo({
					url:'/pages/submit/PastRecords'
				})
			},
			confirm(){
				
				uni.navigateTo({
					url:'/pages/submit/CompleteInformation?userId='+this.userId
				})
			},
			amend(){
				
				let that=this
				that.loadModal=true
				uni.request({
					method:'POST',
					url:App.globalData.baseUrl + '/api/services/app/organUser/IsCanModfied',
					data:{"userId":that.userId,"identityNumber":that.objs.identityNumber},
					success(res) {
					   that.loadModal=false
					   if(res.data.result==true){
						   
						   uni.navigateTo({
						   	url:'/pages/submit/CompleteInformation?userId='+that.userId
						   })
						   
					   }else{
						   
						   uni.showToast({
						   	title:"你当前是操作该用户的辅助账户不能更改班级,请用首次绑定的该用户账户更换",
						   	duration:1000,
						   	icon:'none'	,
						   })
						   
					   }
					  // uni.setStorageSync('storage_key', that.objs);
					  
					},fail(res) {
						that.loadModal=false
						uni.showToast({
							title:res.data.error.message,
							duration:1000,
							icon:'none'	,
						})
					}
				})
				
				// this.IsSet=false
				
			},
			appear(){
				uni.redirectTo({
					url:'/pages/submit/DataReport'
				})
			},
				
			fanhui(){
				uni.navigateBack({
					delta:1
				})
			}
		}
	}
</script>

<style scoped>
	.box{width: 100%;height: 100vh;}
	.head{
		height: 120rpx;
		width: 100%;
		background-color: #FFFFFF;
		padding: 0 30rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 30rpx;
		position: fixed;
		z-index: 10;
	}
	.head_left{
		display: flex;
		align-items: center;
	}
	.head_right{
		position: relative;
	}
	.windows{
		position: absolute;
		top: 60rpx;
		right: 10rpx;
	}
	.windows_box{
		width: 260rpx;
		background: #FFFFFF;
		padding: 0 30rpx;
		box-sizing: border-box;
		box-shadow:0rpx 0rpx 6rpx #000;
		border-radius: 12rpx;
	}
	.windows_box>view{
		width:100%;
		height: 90rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		text-align: center;
		line-height: 90rpx;
	}
	.windows_box>view:nth-child(1),.windows_box>view:nth-child(2){
		border-bottom: 1rpx solid #DDDDDD;
	}
	.dian{height: 150rpx;}
	.content{
		width: 100%;
	}
	.ent_head{
		width: 100%;
		background-color: #FFFFFF;
		padding: 0 30rpx;
		box-sizing: border-box;
		border-radius: 10rpx;
	}
	.names{
		height: 96rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1rpx solid #D8D8D8;
	}
	.names>view:nth-child(1){
		margin-left: 20rpx;
	}	
	.names>view:nth-child(2){
		color:#686868;
	}
	.modification{
		height: 300rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.ent_head>.opp{
		border-bottom: 0rpx;
	}
	.modification>view{
		width: 400rpx;
		height: 100rpx;
		border-radius: 60rpx;
		font-size: 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #FFFFFF;
		background-color: #1CBBB4;
	}
	
	/* 弹窗 */
	.MaskLayer{
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0rpx;
		left: 0rpx;
		background: #000000;
		opacity: 0.6;
	}
	.gif>view>image{width: 160rpx;height: 160rpx;}
	.gif>view>view{color: #FFFFFF;text-align: center;margin-top: 10rpx;font-size: 28rpx;}
	.CPM,.gif{
		width: 100%;
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		position: fixed;
		top: 0;
		left: 0;
	}
	.CPM_box{
		width: 400rpx;
		height: 400rpx;
		border-radius: 50rpx;
		background: rgb(241,241,241);
		padding: 50rpx;
		position: relative;
	}
	.CPM_box>image{
		width: 70rpx;
		height: 70rpx;
		position: absolute;
		right: 10rpx;
		top:-100rpx
	}
	.CPM_box>view:nth-child(2){
		font-size: 34rpx;
		text-align: center;
		margin-top: 20rpx;
	}
	.CPM_box>view:nth-child(3){
		font-size: 30rpx;
		width: 100%;
		height: 80rpx;
		border-radius: 45rpx;
		margin-top: 40rpx;
		background-color: #1CBBB4;
		color: #FFFFFF;
		text-align: center;
		line-height: 80rpx;
	}
	.CPM_box>view:nth-child(4){
		font-size: 30rpx;
		width: 100%;
		height: 80rpx;
		border-radius: 45rpx;
		margin-top: 40rpx;
		background-color: rgb(201,201,201);
		color: #FFFFFF;
		text-align: center;
		line-height: 80rpx;
	}
</style>